var Index = {

    init: function () {
        var self = this;

        $("a.delete_announcement_btn").click(function(){
            var me = $(this);
            var li = me.parent();
            alertify.confirm("Are you sure you want to remove this message ?", function (e) {
                if (e) {
                    // user clicked "ok"
                    self.showMiniBlanket(li);
                    var id = me.attr('data-id');
                    var url = $('#delete_notification').val()+'/'+id;
                    var query = '';
                    $.post(url, query, function (response) {
                        li.addClass("animated fadeOutLeft");
                        setTimeout(function(){
                            self.hideMiniBlanket(li);
                            li.remove();
                        },1000);
                    },'json');
                }
                else {
                    // user clicked "cancel"
                }
            });
        });
    },


    showMiniBlanket:function(parent){
        var self = this;
        self.processMiniBlanket(parent,'show');
    },

    hideMiniBlanket:function(parent){
        var self = this;
        self.processMiniBlanket(parent,'hide');
    },

    processMiniBlanket:function(parent,type){
        var self = this;
        var inner_loader = parent.find("div.inner-loader");
        var mini_blanket = parent.find("div.mini-blanket");
        if(type == 'show'){
            inner_loader.removeClass('hide');
            mini_blanket.removeClass('hide');
        }
        else{
            inner_loader.addClass('hide');
            mini_blanket.addClass('hide');
        }
    }
};

/* when the page is loaded */
$(document).ready(function () {
    Index.init();
});